<template>
  <base-breadcrumb>
    <searchData :search-data="searchArr" @search="search" @changeSelect="changeSelect" :empty='iSempty' :emptyField="emptyField"/>
    <a-card>
      <!-- :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" -->
      <list-table
        :loading="loading.isTable"
        :request="loadData"
        ref="table"
        :columns="columns"
        :startIndex="0"
        :export-config="{ use: true, select: $route.meta.title, all: $route.meta.title }"
        :is-show-count-bar="false"
        @select-click="selectClick"
        :export-permission="{select:'tm_007_exp_06',all:'tm_007_exp_06'}"
      >
        <a-button
          slot="prefix"
          v-btnPermission="'tm_007_add_01'"
          type="primary"
          icon="plus"
          @click="handleAdd"
        >
          新增上报
        </a-button>
        <a-collapse v-model="activeKey" :bordered="false" expand-icon-position="right" slot="suffix" class="mb12">
          <a-collapse-panel style="background: #e6f3fc; border: none" :show-arrow="false">
            <template slot="header">
              <a-row
                type="flex"
                justify="space-between"
                align="middle"
                style="width: 100%"
              >
                <a-spin :spinning="loading.total">
                  <a-icon
                    style="color: #108ee9"
                    type="exclamation-circle"
                  />
                  <span>
                    已选择<a>{{ selectLength || 0 }}</a> 项</span>
                  <span>
                    总计：<a>{{ totalNum  || 0 }}</a></span>
                  <span>
                    待提交审核：<a>{{ totalInfo.draft || 0 }}</a> 个</span>
                  <span>{{ ' | ' }}审核中：<a>{{ totalInfo.submitted || 0 }}</a> 个</span>
                  <span>{{ ' | ' }}审核通过：<a>{{ totalInfo.past || 0 }}</a> 个</span>
                  <span>{{ ' | ' }}审核不通过：<a>{{ totalInfo.rejected || 0 }}</a> 个</span>
                  <span>{{ ' | ' }}施组（方案）计划审批数：<a>{{ totalInfo.planNum || 0 }}</a> 个</span>
                  <span>{{ ' | ' }}已审批方案数：<a>{{ totalInfo.audited || 0 }}</a> 个</span>
                  <span>{{ ' | ' }}施组（方案）审批率：<a>{{ totalInfo.rate || 0 }} %</a>
                  </span>
                  <span>{{ ' | ' }}一般延误率：<a>{{ totalInfo.general || 0 }} %</a>
                  </span>
                  <span>{{ ' | ' }}严重延误率：<a>{{ totalInfo.serious || 0 }} %</a>
                  </span>
                  <span>{{ ' | ' }}TRUE（YB）：<a>{{ totalInfo.trueYb || 0 }} %</a>
                  </span>
                  <span>{{ ' | ' }}TRUE（YZ）：<a>{{ totalInfo.trueYz || 0 }} %</a>
                  </span>
                  <span>{{ ' | ' }}两级机关回退次数：<a>{{ totalInfo.twoFallBacknNum || 0 }}</a>
                  </span>
                  <span>{{ ' | ' }}公司总回退次数：<a>{{ totalInfo.comFallBackNum || 0 }}</a>
                  </span>
                  <span>{{ ' | ' }}两级机关回退率：<a>{{ totalInfo. branchComRate || 0 }} %</a>
                  </span>
                  <span>{{ ' | ' }}公司回退率：<a>{{ totalInfo.comRate || 0 }} %</a>
                  </span>
                </a-spin>
                <div>
                  <a class="btn_right">
                    <span>{{ activeKey.length > 0 ? '收起' : '展开' }}详细汇总信息</span>
                    <a-icon :type="activeKey.length > 0 ? 'up' : 'down'" />
                  </a>
                </div>
              </a-row>
            </template>
            <div class="combox-table-wrapper">
              <s-table
                ref="comBoxTable"
                class="table"
                bordered
                :columns="comboxColumns"
                :data="loadComboxTable"
                row-key="id"
                :show-pagination="false"
              >
                <template
                  slot="rate"
                  slot-scope="text"
                >
                  {{ text | filterRate }}
                </template>
                <template
                  slot="general"
                  slot-scope="text"
                >
                  {{ text | filterRate }}
                </template>
                <template
                  slot="serious"
                  slot-scope="text"
                >
                  {{ text | filterRate }}
                </template>
              </s-table>
            </div>
          </a-collapse-panel>
        </a-collapse>
        <span
          slot="description"
          slot-scope="text,record"
        >
          <ellipsis
            :length="8"
            tooltip
          >{{ text }}</ellipsis>
        </span>
        <span slot="versionNumber" slot-scope="text,record" style="cursor: pointer;color:#108DE9" @click="versionList(record)">
           {{getVersionNumber(text)}}
        </span>
        <span slot="branchStarLevel" slot-scope="text,record" >
           {{getBranchStarLevelStar(record)}}
        </span>
        <span slot="comStarLevel" slot-scope="text,record" >
          {{getComStarLevelStar(record)}}
        </span>
        <!-- 操作 -->
        <span
          slot="operation"
          slot-scope="text, record"
        >
          <MoreButton>
            <a
              v-btnPermission="'tm_007_loo_04'"
              @click="detailed(record)"
            >查看</a>
            <a-divider
              v-selfBtn="record.creatorId"
              v-if="(record.schemeCategory == 'A' && (record.status == 'PAST_CHANGE')) || (record.schemeCategory != 'A' && record.status=='PAST')"
              type="vertical"
              v-btnPermission="'tm_007_rej_08'"
            />
            <a
              v-btnPermission="'tm_007_rej_08'"
              v-if="(record.schemeCategory == 'A' && (record.status == 'PAST_CHANGE')) || (record.schemeCategory != 'A' && record.status=='PAST')"
              @click="changeDetail(record)"
              v-selfBtn="record.creatorId"
            >变更</a>
            <a-divider
            v-if="promoteExcellenceBtn(record)"
              v-btnPermission="'tm_007_tuy_07'"
              v-selfBtn="record.creatorId"
              type="vertical"
            />
            <!-- record.status == 'PAST' && !record.topAuditStatus -->
            <a
            v-if="promoteExcellenceBtn(record)"
              v-btnPermission="'tm_007_tuy_07'"
              @click="promoteExcellenceFn(record)"
              v-selfBtn="record.creatorId"
            >推优</a>
            <!-- 审核中不能进行编辑 -->
            <a-divider
              v-if="record.status == 'DRAFT' || record.status == 'REJECTED'"
              v-btnPermission="'tm_007_edi_02'"
              v-selfBtn="record.creatorId"
              type="vertical"
            />
            <a
              v-if="record.status == 'DRAFT' || record.status == 'REJECTED'"
              v-btnPermission="'tm_007_edi_02'"
              v-selfBtn="record.creatorId"
              @click="addEdit(record, 'edit')"
            >编辑</a>
            <a-divider
            v-if="record.status == 'DRAFT' && record.versionNumber*1<2"
              v-btnPermission="'tm_007_del_03'"
              v-selfBtn="record.creatorId"
              type="vertical"
            />
            <a
              v-if="record.status == 'DRAFT' && record.versionNumber*1<2"
              v-btnPermission="'tm_007_del_03'"
              v-selfBtn="record.creatorId"
              @click="discard(record)"
            >删除</a>
            <a-divider
            v-if="record.schemeCategory == 'A' && (record.status == 'PAST')"
              v-btnPermission="'tm_007_ret_05'"
              type="vertical"
            />
            <!-- v-if="record.schemeCategory == 'A' && (record.status == 'PAST' || record.status == 'REJECTED_CHANGE')" -->
            <a
              v-if="record.schemeCategory == 'A' && (record.status == 'PAST')"
              v-btnPermission="'tm_007_ret_05'"
              @click="addEdit(record, 'change')"
              v-selfBtn="record.creatorId"
            >二次报审</a>
            <a-divider
            v-if="record.schemeCategory == 'A' && (record.status == 'DRAFT_CHANGE' || record.status == 'REJECTED_CHANGE')"
              v-btnPermission="'tm_007_edi_02'"
              type="vertical"
              v-selfBtn="record.creatorId"
            />
              <!-- 二次报审编辑 -->
            <a
              v-if="record.schemeCategory == 'A' && (record.status == 'DRAFT_CHANGE' || record.status == 'REJECTED_CHANGE')"
              v-btnPermission="'tm_007_edi_02'"
              @click="addEdit(record, 'change')"
              v-selfBtn="record.creatorId"
            >编辑</a>
            <a-divider
              v-if="record.status && record.status !== 'DRAFT'"
              v-btnPermission="'tm_007_exa_09'"
              type="vertical"
            />
            <!-- versionNumber大于1一定有审批信息 -->
            <a
              v-if="record.status && record.status !== 'DRAFT' || record.versionNumber*1>1"
              v-btnPermission="'tm_007_exa_09'"
              @click="toggleApprovalDetails(record,1)"
            >审批信息</a>
            <a-divider
            v-if="record.topAuditStatus && record.topAuditStatus!== 'DRAFT' "
              v-btnPermission="'tm_007_exa_09'"
              type="vertical"
            />
            <a
              v-if="record.topAuditStatus && record.topAuditStatus!== 'DRAFT' "
              v-btnPermission="'tm_007_exa_09'"
              @click="toggleApprovalDetails(record,2)"
            >推优审批信息</a>
          </MoreButton>
        </span>

        <template
          slot="status"
          slot-scope="text, record"
        >
          <list-status
            :color="listStatusMap[record.status]"
            :isApproval="true"
            conversion="en"
            :text="text"
          ></list-status>
        </template>
      </list-table>
      <div>
        <!-- <pagination
          :total="total"
          v-model="pageNo"
          :pageSize.sync="pageSize"
          @change="handlePageChange"
          @showSizeChange="showSizeChange"
        ></pagination> -->
        <!-- <pagination
          v-model="objFrom.pageNo"
          :total="totalSize"
          :page-size.sync="objFrom.pageSize"
          @change="onPageNo"
          @showSizeChange="onShowSizeChange"
        /> -->
      </div>
    </a-card>
    <ApprovalDetails
      :visible="visible.approvalDetails"
      :business-id="businessId"
      @cancel="visible.approvalDetails = false"
      @confirm="visible.approvalDetails = false"
    />
    <Version :visible="visible.versionVisible" @cancel="visible.versionVisible = false" :versionId="versionId"></Version>
    <PromoteExcellence :visible="visible.excellenceVisible" @cancel="cancelPromoteExcellence" :excellenceId="excellenceId"></PromoteExcellence>
  </base-breadcrumb>
</template>

<script>
import { STable } from '@/components'
import { Collapse } from 'ant-design-vue' // ant
import ApprovalDetails from '@/components/approvalDetails'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import TitleName from '@/components/TitleName/index.vue'
import { getList, getListTotal, deleteList, getGroupCount, getTotalCount,getAuditApproval} from '@/api/technical/approval'
import { listOption } from '@/api/technical/approvalPlan'
import {getProjectTypes} from '@/api/project/projects'
import Version from './version.vue'   //历史版本号
import PromoteExcellence from './promoteExcellence.vue'    //推优
import { getReviewerList } from '@/api/technical/review'
import { getWbsTemplateList } from '@/api/template'
import { thistle } from 'color-name'
const starData = [
  { label: '1星', value: '1' },
  { label: '2星', value: '2' },
  { label: '3星', value: '3'},
  { label: '4星', value: '4'},
  { label: '5星', value: '5'},
]
const columns = [
  {
    title: '施组（方案名称）',
    dataIndex: 'schemeName',
    ellipsis: true
  },
  {
    title: '方案分类',
    dataIndex: 'schemeCategory',
    ellipsis: true
  },
  {
    title: '所属分公司',
    dataIndex: 'branchCompany'
  },
  {
    title: '所属项目',
    dataIndex: 'projectName'
  },
  {
    title: '版本号',
    dataIndex: 'versionNumber',
    scopedSlots: { customRender: 'versionNumber' }
  },
  {
    title: '分公司审核师星级',
    dataIndex: 'branchStarLevel',
    scopedSlots: { customRender: 'branchStarLevel' }
  },
  {
    title: '公司审核师星级',
    dataIndex: 'comStarLevel',
    scopedSlots: { customRender: 'comStarLevel' }
  },
  {
    title: '方案交底状态',
    dataIndex: 'confessAuditStatusName'
  },
  {
    title: '推优状态',
    dataIndex: 'topAuditStatusStr'
  },
  {
    title: '意见回复状态',
    dataIndex: 'replyStatus'
  },
  {
    title: '填报人',
    dataIndex: 'reportingPeople',
    ellipsis: true
  },
  {
    title: '状态',
    dataIndex: 'statusSer',
    ellipsis: true,
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '填报时间',
    dataIndex: 'reportingTime',
    ellipsis: true
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width: '230px',
    scopedSlots: { customRender: 'operation' }
  }
]
const comboxColumns = [
  {
    title: '方案类别',
    dataIndex: 'type.name'
  },
  {
    title: '计划内应审批总数',
    dataIndex: 'planNum'
  },
  {
    title: '计划内实际审批通过总数',
    dataIndex: 'auditNum'
  },
  {
    title: '计划内审批通过率',
    dataIndex: 'rate',
    scopedSlots: { customRender: 'rate' }
  },
  {
    title: 'A类方案二次报审率',
    dataIndex: 'twoRate'
  },
  // {
  //     title: '一般延误率',
  //     dataIndex: 'general',
  //     scopedSlots: { customRender: 'general' }
  // },
  // {
  //     title: '严重延误率',
  //     dataIndex: 'serious',
  //     scopedSlots: { customRender: 'serious' }
  // }
]
export default {
  name: 'a' + Date.now(),
  components: {
    TitleName,
    SelectSubCompany,
    SelectProject,
    ApprovalDetails,
    ACollapse: Collapse,
    ACollapsePanel: Collapse['Panel'],
    STable,
    Version,
    PromoteExcellence
  },
  filters: {
    filterRate(rate) {
      if (Number.isFinite(rate)) {
        return (rate * 100).toFixed(2) + '%'
      }
      return '0%'
    }
  },
  data() {
    this.columns = columns
    return {
      totalInfo: {}, // 统计信息
      activeKey: [],
      comboxColumns,
      childInitData: {},
      selectLength: 0,
      visible: {
        approvalDetails: false,
        versionVisible:false,
        excellenceVisible:false
      },
      loading: {
        isTable: false,
        exportChecked: false,
        exportAll: false,
        total: false,
      },
      qualityTypes:[],
      dataSource: [],
      advanced: false,
      totalSize: 0,
      option: [],
      total: {},
      reportingTime: [],
      completeDate: [],
      objFrom: {
        pageNo: 1,
        pageSize: 10,

        whetherProfessionalSubcontracting: '',
        whetherMajorExpense: ''
      },
      statusList:[],
      starData,
      selectedRowKeys: [],
      selectedRows: [],
      listStatusMap: {
        DRAFT: 'yellow',
        SUBMITTED: 'blue',
        PAST: 'green',
        REJECTED: 'red',
        DRAFT_CHANGE: 'yellow',
        SUBMITTED_CHANGE: 'blue',
        PAST_CHANGE: 'green',
        REJECTED_CHANGE: 'red'
      },
      pathName: this.$route.path,
      queryParam: {},
      totalNum:0,
      loadData: (parameter) => {
        // if (this.loading.isTable) return
        this.loading.isTable = true
        const { whetherProfessionalSubcontracting, whetherMajorExpense, projectName } = this.objFrom
        const params = {
          // ...this.objFrom,
          ...this.queryParam,
          ...parameter,
          projectName: projectName || void 0,
          // whetherProfessionalSubcontracting: whetherProfessionalSubcontracting !== '' && whetherProfessionalSubcontracting !== void 0 ? !!whetherProfessionalSubcontracting : void 0,
          whetherMajorExpense: whetherMajorExpense !== '' && whetherMajorExpense !== void 0 ? !!whetherMajorExpense : void 0
        }
        if (params.whetherProfessionalSubcontracting){
          params.whetherProfessionalSubcontracting = params.whetherProfessionalSubcontracting == 1 ? true : false
        }
        // this.loadComboxTable(params) // 调用统计分组
        if (this.$refs.comBoxTable) {
          this.$refs.comBoxTable.refresh()
        }
        this.getTotalCountReq(params) // 调用统计信息
        return getList(params)
          .then((res) => {
            this.loading.isTable = false
            this.totalNum = res.totalSize
            return res
          })
          .catch(() => {
            this.loading.isTable = false
          })
      },
      typeOption:[],
      versionId:null,
      companyData:[],  //公司审核师数据
      branchCompanyData:[], //分公司审核师数据
      wbsTemplateList:[], //项目业态
      excellenceId:null,
      auditApprovalData:[],
      schemeA:{
        value:'queryAuditStatusList',
        type:'selectMode'
      },
      iSempty:false,
      emptyField:'',
      isQualityRoute:1,   //是否是质量，还是技术路由
      approvalData:[{ label: '待提交审批', value: '0' },
             { label: '审核中', value: '1' },
             { label: '审核通过', value: '2' },
             { label: '审核不通过', value: '3' },]
    }
  },
  created() {
    this.focusOption()
    this.getProjectTypesFn();
    this.reportingTime = ['2021-01-01', this.$dateFormat(new Date(), 'D')]
    this.changeReportingTime('', this.reportingTime)
    // this.getList()
    // this.getListTotal()
  },
  computed:{
    searchArr() {
      let that = this;
      return [
        { name: '所属单位', valueKey: 'searchQuery', type: OrgTreeSelect, listeners:{
        }},
        { name: '方案名称', value: 'schemeName', type: 'input', },
        { name: '方案类型', value: 'planTypeId',type: 'select', data: this.typeOption,},
        { name: '审批状态', value: this.schemeA.value,  type:this.schemeA.type, data: this.statusList,placeholder:'请先选方案类型'},
        { name: '填报类型', value: 'reportingType', type: 'select', data: [
          { label: '计划内填报', value: '0' },
          { label: '计划外填报', value: '1'},
        ] },
        { name: '是否为专业分包', value: 'whetherProfessionalSubcontracting', type: 'select', data: [
          { label: '是', value: 1 },
          { label: '否', value: 0 },
        ] },
        { name: '是否涉及重大费用诉求', value: 'whetherMajorExpense', type: 'select', data: [
          { label: '是', value: 1 },
          { label: '否', value: 0 },
        ] },
        { name: '填报人', value: 'reportingPeople', type: 'input', },
        { name: '填报时间', value: 'reportingTime', type: 'dateRange', attr: {
          rangeFormat: ['reportingTimeStart', 'reportingTimeEnd'],
          defaultValue: ['2021-01-01', this.$dateFormat(new Date(), 'D')]
        } },
        { name: '项目业态', value: 'projectWbsType', type: 'select', data: this.wbsTemplateList },
        { name: '审批完成时间', value: 'completeDate', type: 'dateRange', attr: { rangeFormat: ['endAuditDateStart', 'endAuditDateEnd'] } },
        { name: '分公司审核师星级', value: 'branchStarLevel', type: 'select', data:this.starData },
        { name: '公司审核师星级', value: 'comStarLevel', type: 'select', data: this.starData},
        { name: '工程类别', value: 'projectQualityTypeId', type: 'select', data: this.qualityTypes},
      ]
    },
    businessId(){
       let id = this.childInitData.isTuiyou*1===1? this.childInitData.id:this.childInitData.topAuditId;
       return id;
    }
  },
  mounted() {
    this.$bus.$on('handleRefresh' + this.pathName, () => {
      console.log('--------------------收到了，刷新刷新刷新----------------', this.pathName)
      this.getList()
    })
    this.getWbsTemplateListFn();
  },
  beforeDestroy() {
    console.log('beforeDestroy-------table的Path', this.pathName)
    this.$bus.$off('handleRefresh' + this.pathName)
  },
  methods: {
    changeSelect(value,item){
      if(item.value=='planTypeId'){
        this.iSempty = true;
        this.emptyField = 'queryAuditStatusList'
        if(value == '634285858551369728'){  //A方案
           this.statusList = [
            { label: '待提交审批', value: '0' },
             { label: '审核中（一次报审）', value: '4' },
             { label: '审核通过（一次报审）', value: '5' },
             { label: '审核不通过（一次报审）', value: '6' },
             { label: '待提交审批（二次报审）', value: '7' },
             { label: '审核中（二次报审）', value: '8' },
             { label: '审核通过（二次报审）', value: '9' },
             { label: '审核不通过（二次报审）', value: '10' }]
        }else if(value){
          this.statusList = this.approvalData;
        }else{
          this.statusList = [];
        }
      }else{
        this.iSempty = false;
        this.emptyField = 'queryAuditStatusList'
      }
    },
    //推优按钮显示控制
    promoteExcellenceBtn(record){
      let flag = false;
      if(record.schemeCategory == 'A' ){ //PAST_CHANGE A类二次通过 !record.topAuditStatus没有推优，REJECTED 推优不通过，DRAFT推优待处理
        if(record.status=='PAST_CHANGE' && (!record.topAuditStatus || record.topAuditStatus == 'REJECTED' )){
          flag = true;
        }else{
          flag = false;
        }
      }else{
        //post 其他通过
        if(record.status=='PAST' && (!record.topAuditStatus || record.topAuditStatus == 'REJECTED')){
          flag = true;
        }else{
          flag = false;
        }
      }
      return flag;
    },
    getBranchStarLevelStar(text){
       let textName = text.branchStarLevel? text.branchStarLevel + '星':'';
       return textName;
    },
    getComStarLevelStar(text){
       let textName = text.comStarLevel? text.comStarLevel + '星':'';
       return textName;
    },
    getVersionNumber(text){
      let textName = text? 'V'+ text:'';
       return textName;
    },
    selectClick(a, b) {
      this.selectLength = a.rows.length
    },
    //点击查看版本号
    versionList(data){
     this.visible.versionVisible = true;
     this.versionId = data.id;
    },
    handleExportChecked() {
      const list = this.selectedRows
      const columns = this.columns
      this.$refs.exportBtnOne.generateExcel(list, { columns: columns }, 0)
    },
    async getTotalCountReq(params) {
      try {
        
        this.loading.total = true
        this.loading.isTable = true
        const res = await getTotalCount(params)
        this.loading.isTable = false;
        this.loading.total = false;
        this.totalInfo = res.data
        if (Number.isFinite(this.totalInfo.rate)) {
          this.totalInfo.rate = (this.totalInfo.rate * 100).toFixed(2)
        } else {
          this.totalInfo.rate = 0
        }
        this.totalInfo.general = Number.isFinite(this.totalInfo.general) ? (this.totalInfo.general * 100).toFixed(2) : 0
        this.totalInfo.serious = Number.isFinite(this.totalInfo.serious) ? (this.totalInfo.serious * 100).toFixed(2) : 0
        this.totalInfo.branchComRate = Number.isFinite(this.totalInfo.branchComRate) ? (this.totalInfo.branchComRate * 100).toFixed(2) : 0
        this.totalInfo.comRate = Number.isFinite(this.totalInfo.comRate) ? (this.totalInfo.comRate * 100).toFixed(2) : 0
        this.totalInfo.trueYb = Number.isFinite(this.totalInfo.trueYb) ? (this.totalInfo.trueYb * 100).toFixed(2) : 0
        this.totalInfo.trueYz = Number.isFinite(this.totalInfo.trueYz) ? (this.totalInfo.trueYz * 100).toFixed(2) : 0
      } catch (e) {
        this.loading.total = false
        console.error(e)
      }
    },
    loadComboxTable(parameter) {
      const { whetherProfessionalSubcontracting, whetherMajorExpense, projectName } = this.objFrom
      const params = {
        ...this.objFrom,
        ...this.queryParam,

        projectName: projectName || void 0,
        whetherProfessionalSubcontracting: whetherProfessionalSubcontracting !== '' && whetherProfessionalSubcontracting !== void 0 ? !!whetherProfessionalSubcontracting : void 0,
        whetherMajorExpense: whetherMajorExpense !== '' && whetherMajorExpense !== void 0 ? !!whetherMajorExpense : void 0
      }
      return getGroupCount(params).then((res) => {
        const list = res.data || []
        // 需要按照该顺序重新对数据排序
        const rankList = ['A', 'B', 'C', 'D', '施组']
        list.sort((x, y) => {
          const xIndex = rankList.indexOf(x?.type?.name)
          const yIndex = rankList.indexOf(y?.type?.name)
          return xIndex - yIndex
        })
        return {
          data: list
        }
      })
    },
    toggleApprovalDetails(data,flag) {
      let isTuiyou = {isTuiyou:flag}
      this.childInitData = { ...data,...isTuiyou};
      this.visible.approvalDetails = true
       if(data.schemeCategory=='A' && data.status =='SUBMITTED'){
       }else{
        this.getAuditApprovalFn(data)
       }
    },
    // 统计
    // getListTotal() {
    //     getListTotal().then((res) => {
    //         this.total = res.data
    //     })
    // },
    focusOption() {
      this.listOptionFn()
    },
    changeReportingTime(value, dateString) {
      this.objFrom.reportingTimeStart = dateString[0]
      this.objFrom.reportingTimeEnd = dateString[1]
    },
    // 类别下拉
    listOptionFn() {
      listOption({ type: '5' }).then((res) => {
        this.typeOption = res.data;
        if(this.typeOption.length){
          this.typeOption.map((item)=>{
            item.label = item.name;
            item.value = item.id;
          })
        }
        this.searchTypeList = this.typeOption;
      })

    },
    // 获取列表数据
    search(val = {}) {
      let flag = false;
      Object.keys(val).forEach((key) => {
         if(val[key]){  //有值就是搜索，否则就是重置
           flag = true;
         }
        })
        if(!flag){
          this.statusList = [];
        }
      this.queryParam = {
        ...val
      }
      this.$refs.table.refresh(true)
    },
    getList() {
      this.$refs.table.refresh(true)
      // if (this.loading.isTable) return
      // this.loading.isTable = true
      // const { whetherProfessionalSubcontracting, whetherMajorExpense, projectName } = this.objFrom
      // const params = {
      //   ...this.objFrom,

      //   projectName: projectName || void 0,
      //   whetherProfessionalSubcontracting:
      //     whetherProfessionalSubcontracting !== '' && whetherProfessionalSubcontracting !== void 0
      //       ? !!whetherProfessionalSubcontracting
      //       : void 0,
      //   whetherMajorExpense:
      //     whetherMajorExpense !== '' && whetherMajorExpense !== void 0 ? !!whetherMajorExpense : void 0
      // }
      // // this.loadComboxTable(params) // 调用统计分组
      // if (this.$refs.comBoxTable) {
      //   this.$refs.comBoxTable.refresh()
      // }
      // this.getTotalCountReq(params) // 调用统计信息
      // getList(params)
      //   .then(res => {
      //     this.loading.isTable = false
      //     this.dataSource = res.data
      //     this.totalSize = res.totalSize
      //   })
      //   .catch(() => {
      //     this.loading.isTable = false
      //   })
    },
    changeTime(value, dateString) {
      this.objFrom.reviewEndTimeStart = dateString[0]
      this.objFrom.reviewEndTimeEnd = dateString[1]
    },
    onShowSizeChange(current, pageSize) {
      this.objFrom.pageNo = current
      this.objFrom.pageSize = pageSize
      this.getList()
    },
    onPageNo(page, pageSize) {
      this.objFrom.pageNo = page
      this.objFrom.pageSize = pageSize
      this.getList()
    },
    // 收起展开
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    //新增
    handleAdd() {
      this.$router.push({
        path: '/technical/ShiGroup/Approval/EditFrom',
        query: {
          type: 'add',
          isQualityRoute:this.isQualityRoute
        }
      })
    },
    //编辑
    addEdit(record, type) {
      if(record.versionNumber*1>1){  //大于1的就是变更编辑
        this.changeDetail(record)
      }else{
        this.$router.push({
        path: '/technical/ShiGroup/Approval/EditFrom',
        query: {
          type,
          id: record.id,
          isQualityRoute:this.isQualityRoute
        }
      })
      }
    },
    //查看
    detailed(record) {
      this.$router.push({
        path: '/technical/ShiGroup/Approval/EditFrom',
        query: {
          type: 'view',
          id: record.id
        }
      })
    },
    //变更
    changeDetail(record){
      let isSchemeCategoryA = record.schemeCategory === 'A' ? 1 : 0;  //是否是A方案
      this.$router.push({
        path: '/technical/ShiGroup/Approval/EditFrom',
        query: {
          type: 'changeDetail',
          id: record.id,
          isSchemeCategoryA,
          isQualityRoute:this.isQualityRoute
        }
      })

    },
    discard(record) {
      let _this = this
      this.$confirm({
        title: '温馨提示',
        content: '确定是否删除数据？',
        okText: '确认',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          return deleteList({ id: record.id }).then((res) => {
            if (res.code == '200') {
              _this.$message.success('删除成功')
            }
            if (res) {
              _this.getList()
            }
          })
        },
        onCancel() {}
      })
    },
    addEmpty() {
      this.completeDate = ''
      // this.changeReportingTime = ''
      this.objFrom = {
        pageNo: 1,
        pageSize: 10,

        whetherProfessionalSubcontracting: '',
        whetherMajorExpense: ''
      }
      this.reportingTime = []
      this.getList()
    },
    //获取工程类别
    getProjectTypesFn() {
      this.type0loading = true
      getProjectTypes().then((res) => {
        this.qualityTypes = res.data?.filter(i => i.status*1 === 1)
        if(this.qualityTypes.length>0){
          this.qualityTypes.map((item)=>{
            item.value = item.projectTypeId;
            item.label = item.projectTypeName
          })
        }
        this.type0loading = false
      })
    },
    //推优
    promoteExcellenceFn(data){
      this.visible.excellenceVisible = true;
      this.excellenceId = data.id;
    },
    //推优成功
    cancelPromoteExcellence(flag){
      this.visible.excellenceVisible = false;
      flag &&  this.$refs.table.refresh(true)
    },
    //获取项目业态
  getWbsTemplateListFn(){
    let params = {
      pageNo:1,
      pageSize:1000000
    }
    getWbsTemplateList(params).then((res)=>{
      if(res.code == '200'){
        this.wbsTemplateList = res.data;
          if(this.wbsTemplateList.length){
            this.wbsTemplateList.map((item)=>{
              item.label = item.formatName;
              item.value = item.formatId
            })
          }
        }
     })
 },
  //查询当前施组的审批节点
  getAuditApprovalFn(data) {
      let parms = {
        versionNumber:data.versionNumber,
        programId:data.id,
      }
      getAuditApproval(parms).then((res)=>{
        if(res.code == 200){
          this.auditApprovalData = res.data;
        }
      })
    },
  }
}
</script>

<style lang="less">
.not-submit {
  display: inline-block;
  padding: 0;
  li {
    list-style: none;
    color: red;
  }
}
.submitted {
  display: inline-block;
  padding: 0;
  li {
    list-style: none;
    color: green;
  }
}
</style>
<style scoped lang="less">
.combox-table-wrapper {
  .table {
    width: 50%;
    background-color: #ffffff;
  }
}
</style>
